﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Configuration;
using System.Text.RegularExpressions;
using System.Web.UI;
using System.Net;
using Visa.Common.SecurityJson;

namespace Visa.Common.MvcContronller
{
    public class UTController : Controller
    {
        private UTContext utContext = null;
        public UTContext UtContext
        {
            get
            {
                if (utContext == null)
                {
                    utContext = Session[UTContext.SessionContextKey] as UTContext;
                    if (utContext == null)
                    {
                        utContext = new UTContext();
                        Session[UTContext.SessionContextKey] = utContext;
                    }
                }
                return utContext;
            }
            private set { utContext = value; }
        }

        public JsonResult JsonError(string message)
        {
            JsonResualt response = new JsonResualt() { Status = JsonResualt.OperationFailure, Message = message };
            return new JsonResult() { Data = response };
        }

        public JsonResult JsonSuccess(string redirectUrl, string message = null)
        {
            JsonResualt response = new JsonResualt();
            response.Status = JsonResualt.OperationSuccess;
            response.RedirectUrl = redirectUrl;
            response.Message = message;

            return new JsonResult() { Data = response };
        }

        public bool IsValidEmailAddress(string s)
        {
            if (string.IsNullOrEmpty(s))
                return false;

            Regex re = new Regex(@"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");
            if (re.IsMatch(s))
                return true;
            else
                return false;
            
        }

        public bool IsNumber(string text)
        {
            Regex regex = new Regex(@"^[-+]?[0-9]*\.?[0-9]+$");
            return regex.IsMatch(text);
        }
       
    }
}
